<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/css/main.css" type="text/css">

    <script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.11.5/sweetalert2.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.11.5/sweetalert2.min.css" />
    <title>发布领域</title>
</head>

<body>
    <div class="header">
        <span class="leftpoint"></span>
        <a href="/hd/node/parentlist" class="lab selected btn">发布领域</a>
        <a class="lab btn">发布节点</a>
        <a href="/hd/editlist" class="lab btn">编辑记录</a>
        <a href="/hd/recordlist" class="lab btn">更改申请</a> {{template "hd/nav.html" .}}
    </div>
    <div class="nav-bar">
        <span class="nav-title">发布领域</span>
        <span class="nav-smtitle">子领域</span>
    </div>
    <div class="main">
        <div class="edittable">
            <div class="tabletitle"><span class="tabletitle-sm">{{if eq .CurrentNode.Type 0}}个人用户{{else}}企业用户{{end}} </span></div>
            <div class="tablehint">
                <span class="row5 hint">领域</span>
                <span class="row5 hint">时间</span>
                <span class="row5 hint">发布人</span>
                <span class="row5 hint">制作人</span>
                <span class="row5 hint"></span>
            </div>

            {{range .Node}}
            <div class="tablecrow">
                <span class="row5 row-title"><img class="btn" onclick="edit({{.Id}})" src="/img/edit.png" style="margin-right:10px">{{.Title}}</span>
                <span class="row5 row-content">{{date .UpdateTime "Y-m-d"}}</span>
                <span class="row5 row-content">{{.CreatorId | getNickName}}</span>
                <span class="row5 row-content">{{.EditorId | getNickName}}</span>
                <span class="row5 row-button btn" onclick="javascript:window.location.href='/hd/node/childlist?FatherNode={{.Id}}'">编辑子领域</span>&nbsp;
                <span class="row5 row-button btn" onclick="javascript:window.location.href='/hd/node?Id={{.Id}}'">发布导图</span>
            </div>
            {{else}}
            <div class="tablecrow">
                <span class="row5 row-content">没有子节点</span>
            </div>
            {{end}}

            <div class="tablecrow">
                <span style="width: 100%;text-align: center;display: block"><img class="btn" onclick="add()" style="vertical-align: middle" src="/img/add.png"></span>
            </div>
        </div>
    </div>
    <script>
        var url = "/hd/node/add";
        function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)return unescape(r[2]);
        return null;
    }
        function add() {
            swal({
                title: '请输入子领域名称',
                input: 'text',
                showCancelButton: true,
                confirmButtonText: 'Submit',
                showLoaderOnConfirm: true,
                preConfirm: function(name) {
                    return new Promise(function(resolve, reject) {
                        setTimeout(function() {
                            if (name === '') {
                                reject('请勿留空。');
                            } else {
                                resolve();
                            }
                        }, 20);
                    });
                },
                allowOutsideClick: false
            }).then(function(name) {
                $.post("/hd/node/add", {
                    Title: name,
                    FatherNode: GetQueryString('FatherNode'),
                    Status: 0,
                    Type: 1,
                    Content: "",
                    CreatorId: {{.uid}},
                    EditorId: {{.uid}}
                }, function(data) {
                    swal({
                        type: 'success',
                        title: '添加成功',
                        html: '添加了领域：' + name
                    }).then(function() {
                        window.location.reload();
                    });
                })
            })
        }

        function edit(id) {
            swal({
                title: '请输入子领域名称',
                input: 'text',
                showCancelButton: true,
                confirmButtonText: 'Submit',
                showLoaderOnConfirm: true,
                preConfirm: function(name) {
                    return new Promise(function(resolve, reject) {
                        setTimeout(function() {
                            if (name === '') {
                                reject('请勿留空。');
                            } else {
                                resolve();
                            }
                        }, 2000);
                    });
                },
                allowOutsideClick: false
            }).then(function(name) {
                $.post("/hd/node/update", {
                    Id: id,
                    Title: name,
                    FatherNode: 0,
                    Status: 0,
                    Type: 1
                }, function(data) {
                    window.location.reload();
                    swal({
                        type: 'success',
                        title: '修改成功',
                        html: '修改领域：' + name
                    });
                })
            })
        }
    </script>
</body>

</html>